package com.test.memory.leak;

import java.util.HashSet;

public class MemoryLeaker {

	private final static int MAX = 10000;

	static HashSet myContainer = new HashSet();

	public void leak(int num) {
		for (int i = 0; i < num; i++) {
			String leakUnit = new String("LeakUnit-" + i);
			System.out.println("adding " + i);
			myContainer.add(leakUnit);
		}
		System.out.println("adding finished");
	}

	public static void main(String[] args) {
		MemoryLeaker ml = new MemoryLeaker();
		for (int i = 0; i < 1000; i++) {
			ml = new MemoryLeaker();
			try {
				Thread.sleep(1000 * 3);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}

			System.out.println("begin..." + i);
			ml.leak(MAX);
			System.out.println("end...");
		}

	}

}
